﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace WPF各种控件样式.TTreeListView
{
    /// <summary>
    /// Interaction logic for TreeListtWindow.xaml
    /// </summary>
    public partial class TreeListtWindow : Window
    {
        public TreeListtWindow()
        {
            InitializeComponent();

            Init();
        }

        private void Init()
        {
            List<ObjTreeGridModel> rootlist = new List<ObjTreeGridModel>();
            for (int i = 0; i < 2; i++)
            {
                ObjTreeGridModel obj = new ObjTreeGridModel();
                obj.ID = Guid.NewGuid().ToString();
                obj.Code = "【Code】A编码" + (i).ToString();
                obj.Name = "【Name】A节点" + (i).ToString();
                obj.Foreground = Brushes.Red;
                for (int j = 0; j < 3; j++)
                {
                    ObjTreeGridModel objChild = new ObjTreeGridModel();
                    objChild.ID = Guid.NewGuid().ToString();
                    objChild.Code = "【Code】B编码" + (i + j).ToString();
                    objChild.Name = "【Name】B节点" + (i + j).ToString();
                    objChild.Foreground = Brushes.Blue;
                    for (int k = 0; k < 5; k++)
                    {
                        ObjTreeGridModel objChild2 = new ObjTreeGridModel();
                        objChild2.ID = Guid.NewGuid().ToString();
                        objChild2.Code = "【Code】B编码" + (i + j + k).ToString();
                        objChild2.Name = "【Name】B节点" + (i + j + k).ToString();
                        objChild2.Foreground = Brushes.GreenYellow;
                        objChild.Children.Add(objChild2);
                    }
                    obj.Children.Add(objChild);
                }
                rootlist.Add(obj);
            }


            this._list.ItemsSource = rootlist;
        }

        private void InitData()
        {
            List<XmlDataModel> xmllist = new List<XmlDataModel>();
            xmllist.Add(new XmlDataModel() { BCode = "B01", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B02", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B03", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B04", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B05", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B06", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B07", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B08", BName = "BN01", TCode = "T01", TName = "TN01" });
            xmllist.Add(new XmlDataModel() { BCode = "B09", BName = "BN01", TCode = "T01", TName = "TN01" });
        }
    }


    public class ObjTreeGridModel : INotifyPropertyChanged
    {
        private void OnPropertyChanged(string prop)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(prop));
        }
        public event PropertyChangedEventHandler PropertyChanged;
        public ObjTreeGridModel() { _children = new ObservableCollection<ObjTreeGridModel>(); }


        public Brush _Foreground;
        public Brush Foreground { get { return _Foreground; } set { _Foreground = value; OnPropertyChanged("Foreground"); } }

        public string ID { get; set; }

        public string _Code;
        public string Code { get { return _Code; } set { _Code = value; OnPropertyChanged("Code"); } }

        public string _Name;
        public string Name { get { return _Name; } set { _Name = value; OnPropertyChanged("Name"); } }

        /// <summary>
        /// 节点图片
        /// </summary>
        public string ItemIcon { get { return _ItemIcon; } set { _ItemIcon = value; OnPropertyChanged("ItemIcon"); } }
        public string _ItemIcon;

        public double _MarginLeft;
        public double MarginLeft { get { return _MarginLeft; } set { _MarginLeft = value; OnPropertyChanged("MarginLeft"); } }

        private bool _isChecked = false;
        public bool IsChecked
        {
            get
            {
                return _isChecked;
            }
            set
            {
                _isChecked = value;
                OnPropertyChanged("IsChecked");
            }
        }

        public object Obj { get; set; }

        public ObjTreeGridModel Parent { get; set; }

        private ObservableCollection<ObjTreeGridModel> _children;
        public ObservableCollection<ObjTreeGridModel> Children
        {
            get { return _children; }
            set { _children = value; OnPropertyChanged("Children"); }
        }

    }

    public class XmlDataModel
    {
        /// <summary>
        /// 编码
        /// </summary>
        public string TCode { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string TName { get; set; }

        public string BCode { get; set; }

        public string BName { get; set; }

        public bool IsOk { get; set; }
    }
}
